package logic

import (
	"context"
	"errors"
	"person/models/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailLogic {
	return &UserDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 用户详情
func (l *UserDetailLogic) UserDetail(in *personrpc.UserDetailRequest) (*personrpc.UserDetailResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	err := user.UserDetail(mysql.DB, in.UserId)
	if err != nil {
		return nil, errors.New("用户详情查询失败")
	}
	return &personrpc.UserDetailResponse{
		Phone:    user.Phone,
		Password: user.Password,
		Age:      user.Age,
		Address:  user.Address,
	}, nil
}
